package org.diy.traffic.config;
/**
 * 
 * @author Shanks Krishnan
 * 
 * The DIYCity class encapsulates the information on each city in the Config File. It contains the following properties
 * 
 * <ul>
 * <li>cityName		String. The Name of the city in the format "city=<name of city>"
 * <li>stateCode	String. The state code in the format "state=<state code>"
 * <li>updateInterval String. Although a numeric value this is represented as a string here. This value can be converted to an integer by using the valueOf method.
 * <li>trafficServiceURL String. The Traffic Service Update URL for this city. The URL is generated automatically at the time of construction
 * </ul>
 *
 */
public class DIYCity {
	public String cityName;
	public String stateCode;
	public int checkInterval;
	
	public String twitterName;
	public String twitterPassword;
	public int maxUpdates;
	
	
	
	/**
	 * The class constructor takes the cityName, stateCode and updateInterval as string values and automatically generates the URL
	 * The constructor adds Yahoo REST api specific tags to the data. This must be overridden if a service other than Yahoo is being used.
	 * @param cityName		String. Name of the city
	 * @param stateCode		String. Two letter State Code
	 * @param checkInterval String. Numeric value of the interval
	 */
	
	public DIYCity(String cityName, String stateCode,
			String tName, String tPass){		
		
		this.cityName=cityName;
		this.stateCode=stateCode;

		
		this.twitterName = tName;
		this.twitterPassword = tPass;
	}
	
	public DIYCity(String cityName, String stateCode, String checkInterval,
			String tName, String tPass, String maxUpdates){		
		
		this.cityName=cityName;
		this.stateCode=stateCode;
		this.checkInterval= Integer.parseInt(checkInterval);
		
		this.twitterName = tName;
		this.twitterPassword = tPass;
		this.maxUpdates = Integer.parseInt(maxUpdates);
	}
	
	public String getEncodedAddress() {
		 return this.cityName.replace(" ", "-") +
		 	"_" + this.stateCode;
	}
	
	/**
	 * This method is called by the DIYConfig class to get all the city configuration information to write into the Config.diy file
	 * 
	 * @return String. The Text block that is used by DIYConfig class to write into the Config file
	 */
	public String seralizeCity(){
		return cityName+"\r\n"+stateCode+"\r\n"+checkInterval+"\r\n"+"#\r\n";
		
	}
	
}
